﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Windows.Forms;
using com.YiXiong.XML;

namespace QYWebSiteBN
{
    public partial class Form_WebSite : Form
    {
        private readonly static string WebSiteFile = ConfigurationSettings.AppSettings["WebSiteFile"];

        public Form_WebSite()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string websitename=txtName.Text;
            if (string.IsNullOrEmpty(websitename))
            {
                MessageBox.Show("名称不能不空!");
                return;
            }
            if (string.IsNullOrEmpty(txtUrl.Text))
            {
                MessageBox.Show("网址不能为空!");
                return;
            }

            string file = string.Format("{0}/{1}", System.IO.Directory.GetCurrentDirectory(), WebSiteFile);


            XMLHelper xml = new XMLHelper(file);
            if (xml.ExistNode(websitename))
            {
                MessageBox.Show("名称已经存在!");
                return;
            }
            else
            {
                 XmlAttributeCollection ac = new XmlAttributeCollection();
                ac.Add(new XmlAttribute("Name","ASP.NET"));
                ac.Add(new XmlAttribute("URL","http://www.qy.com.cn"));
                xml.AddNode("WebSites", "WebSite", string.Empty, ac);
                xml.Save();
                this.Close();
            }

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
